package com.wqh.ice.demo;

import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.Identity;
import com.zeroc.Ice.Object;
import com.zeroc.Ice.ObjectAdapter;
import com.zeroc.Ice.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class Server {
    private static Logger logger = Logger.getLogger(Server.class.getSimpleName());

    public static void main(String[] args) {
        int status = 0;
        List<String> extraArgs =new ArrayList<>();


        //根据配置文件创建通信器
        try(Communicator com = Util.initialize(args,"config.server",extraArgs)){
            com.getProperties().setProperty("Ice.Default.Package","com.zeroc.demos.Ice.demo");

            //安装shutdown钩子，以便在JVM关闭期间销毁通信器。这确保通信器在用户按Ctrl-C中断应用程序时被销毁
            Runtime.getRuntime().addShutdownHook(new Thread(()->com.destroy()));

            if(!extraArgs.isEmpty()){
                System.err.println("参数异常");
            }else{
                //为通信器创建适配器
                ObjectAdapter adapter = com.createObjectAdapter("Hello");
                adapter.add(new HelloServiceI(),Util.stringToIdentity("helloService"));

                adapter.activate();
                logger.info("server服务器已经启动。。。");
                com.waitForShutdown();
            }
        }
        System.exit(status);









    }
}
